package com.kpx.app.base;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kpx.app.R;
import com.kpx.app.activity.ActivityLogin;
import com.kpx.app.activity.ActivityMain;
import com.kpx.app.activity.ActivitySplash;
import com.kpx.app.activity.ActivityWelcome;
import com.kpx.app.cache.MemoryCache;
import com.kpx.app.configs.BroadcastFilters;
import com.kpx.app.configs.Constants;
import com.kpx.app.configs.MyActivityManager;
import com.kpx.app.http.HttpDataApi;
import com.kpx.app.http.HttpDataApi.OnRequestCallback;
import com.kpx.app.http.HttpDataLoader;
import com.kpx.app.http.ResObj;
import com.kpx.app.listener.SimpleViewPropertyAnimatorListener;
import com.kpx.app.service.UploadService;
import com.kpx.app.utils.HandlerManager;
import com.kpx.app.utils.StringUtil;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.utils.UserInfoUtils;
import com.kpx.app.utils.datautils.LogUtils;
import com.kpx.app.utils.systemutils.SystemUtil;
import com.kpx.app.utils.uiutils.DisplayUtil;
import com.kpx.app.utils.uiutils.IntentUtil;
import com.kpx.app.utils.uiutils.ToastUtil;
import com.kpx.app.view.TitleView;
import com.kpx.app.wigdet.LoadingDialog;

import org.apache.http.HttpStatus;
import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnPermissionDenied;
import permissions.dispatcher.OnShowRationale;
import permissions.dispatcher.PermissionRequest;

/**
 * User: 陈聪(617909447@qq.com)
 * Date: 2016-07-06
 * Time: 09:20
 * FIXME
 */
@permissions.dispatcher.RuntimePermissions
public abstract class ActivityBase extends AppCompatActivity implements OnRequestCallback {
    /**
     * 广播过滤器
     */
    private IntentFilter intentFilter;
    /**
     * 广播接收
     */
    private BroadcastReceiver receiver;
    /**
     * 数据加载对象
     */
    private HttpDataLoader loader;
    private LoadingDialog mDialog;
    protected static List<ActivityBase> openedActivities = new ArrayList<>();
    private ArrayList<ActivityDelegate> mDelegates = new ArrayList<>();
    private boolean isUploadServiceAlive = true;
    private PopupWindow mNetworkStatusBar;
    private boolean mActivityLoadingFinished = false;
    private HandlerManager mMainHandler = new HandlerManager(this);
    private Runnable mCheckStatusTask;
    private LinearLayout mContentView;
    private TitleView basetitleView;
    private WakefulBroadcastReceiver wakefulBroadcastReceiver;
    private LinearLayout warningView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!(this instanceof ActivitySplash) && !(this instanceof ActivityWelcome)) {
            UIUtils.setNotifyColor(this, R.drawable.main_title_bg);
        }
        if (mDelegates.size() > 0) {
            for (ActivityDelegate delegate : mDelegates) {
                delegate.onCreate(savedInstanceState);
            }
        }
//        if (!EventBus.getDefault().isRegistered(this)) {
//            EventBus.getDefault().register(this);
//        }
        openedActivities.add(this);
        MyActivityManager.newInstance().push(this);
        registReceiver();
        initView();
        initview(savedInstanceState);
        initData();
        if (SystemUtil.getConnectivityType(this) == SystemUtil.TYPE_NOT_CONNECTED) {
            showWarningView(true, "");
        }
        wakefulBroadcastReceiver = new WakefulBroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                NetworkInfo.State state = SystemUtil.getConnectivityStatus(getApplication());
                LogUtils.d("main", "网络状态:" + state.name());
                switch (state) {
                    case CONNECTED:
                        showWarningView(false, "");
                        break;
                    case DISCONNECTED:
                        showWarningView(true, "");
                        break;
                }
            }
        };
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        registerReceiver(wakefulBroadcastReceiver, intentFilter);
    }

    private void initView() {
        if (this instanceof ActivitySplash || this instanceof ActivityWelcome) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);  //无title
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏
        }
        super.setContentView(R.layout.activity_base);
        basetitleView = (TitleView) findViewById(R.id.basetitleview);
        basetitleView.setBackFinish();
        basetitleView.setBackgroundResource(R.drawable.main_title_bg);
        if (null != basetitleView) {
            setTitleVisible(false);
        }
    }

    public void setContentView(int layoutResID) {
        View contentView = LayoutInflater.from(this).inflate(layoutResID, null, false);
        addContentView(contentView);
    }

    public void addContentView(View contentView) {
        inflateContentView();
        mContentView.removeAllViews();
        mContentView.addView(contentView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    }

    private void inflateContentView() {
        if (null == mContentView) {
            ViewStub contentViewStub = (ViewStub) findViewById(R.id.contentViewStub);
            mContentView = (LinearLayout) contentViewStub.inflate().findViewById(R.id.contentViewContainer);
        }
    }

    /**
     * 设置代理类,处理生命周期等相关触发方法
     *
     * @param delegate
     */
    public void addDelegate(ActivityDelegate delegate) {
        if (null != delegate && !mDelegates.contains(delegate)) {
            mDelegates.add(delegate);
        }
    }

    //---------网络请求操作------start-------------------------------------------------------------------------
    @Override
    public void onRequestSuccess(String url, ResObj result, boolean isFrmCache) {
        if (Constants.CODE_SUCCESS != result.getCode()
                && HttpDataApi.OnRequestCallback.CODE_NEED_RELOGIN != result.getCode()
                && HttpDataApi.OnRequestCallback.CODE_NEED_NOTLOGIN != result.getCode()) {
            doRequestError(url, HttpStatus.SC_OK, result.getMsg());
        }
    }

    public void doRequestError(String url, int code, String message) {
        if (HttpStatus.SC_OK == code) {
            dissmissLoadingDialog();
            if (TextUtils.isEmpty(message)) {
                message = getString(R.string.server_busy_retry_later);
            }
            ToastUtil.getInstance().showDialog(this, message);
            // 会话过期错误码特殊处理
            if (ResObj.CODE_INVALID_TOKEN == code || ResObj.CODE_TOKEN_EXPIRED == code || ResObj.CODE_COMPLETE_INFO == code) {
                UserInfoUtils.loginOut();
                Intent intent = new Intent(this, ActivityLogin.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        } else {
            dissmissLoadingDialog();

            String msg = message;
            switch (code) {
                case HttpDataApi.OnRequestCallback.CODE_NETWORK_TIME_OUT: {
                    msg = getString(R.string.tip_network_time_out);
                    break;
                }
                case HttpDataApi.OnRequestCallback.CODE_AUTH_FAILURE:
                case HttpDataApi.OnRequestCallback.CODE_REDIRECT_ERROR:
                case HttpDataApi.OnRequestCallback.CODE_SERVER_ERROR: {
                    msg = getString(R.string.server_busy_retry_later);
                    break;
                }
                case HttpDataApi.OnRequestCallback.CODE_NETWORK_ERROR: {
                    msg = getString(R.string.tip_network_error);
                    break;
                }
                case HttpStatus.SC_INTERNAL_SERVER_ERROR:
                    if (TextUtils.isEmpty(msg)) {
                        msg = getString(R.string.server_busy_retry_later);
                    }
                    break;
            }
            ToastUtil.getInstance().showDialog(this, msg);
        }
    }

    @Override
    public void onRequestError(String url, int statusCode, String error) {
        doRequestError(url, statusCode, error);
    }

    //---------生命周期操作------start-------------------------------------------------------------------------
    @Override
    protected void onStart() {
        super.onStart();
        if (mDelegates.size() > 0) {
            for (ActivityDelegate delegate : mDelegates) {
                delegate.onStart();
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mDelegates.size() > 0) {
            for (ActivityDelegate delegate : mDelegates) {
                delegate.onResume();
            }
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mDelegates.size() > 0) {
            for (ActivityDelegate delegate : mDelegates) {
                delegate.onPause();
            }
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mDelegates.size() > 0) {
            for (ActivityDelegate delegate : mDelegates) {
                delegate.onStop();
            }
        }
        if (null != mNetworkStatusBar) {
            mNetworkStatusBar.dismiss();
            mNetworkStatusBar = null;
        }
    }

    @Override
    protected void onDestroy() {
        unregisterReceiver(receiver);
        unregisterReceiver(wakefulBroadcastReceiver);
        dissmissLoadingDialog();
        super.onDestroy();
        if (loader != null) {
            loader.finish();
        }
        MyActivityManager.newInstance().remove(this);
        if (mDelegates.size() > 0) {
            for (ActivityDelegate delegate : mDelegates) {
                delegate.onActivityDestroy();
            }
        }
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        if (null != mCheckStatusTask) {
            mMainHandler.removeCallbacks(mCheckStatusTask);
        }
        MemoryCache.sharedInstance().clear(getClass().getName());
        dissmissLoadingDialog();
    }
//---------basetitleView操作------start-------------------------------------------------------------------------

    public void setTitleVisible(boolean b) {
        basetitleView.setVisibility(b ? View.VISIBLE : View.GONE);
    }

    public void setTitleStr(String title) {
        if (basetitleView != null) {
            setTitleVisible(true);
            basetitleView.setTitle(title);
        }
    }

    public void setTitleStr(int title) {
        if (basetitleView != null) {
            setTitleVisible(true);
            basetitleView.setTitle(title);
        }
    }

    public TitleView gettitleView() {
        return basetitleView;
    }

//---------basetitleView操作------end-------------------------------------------------------------------------

    //---------网络状态监听------start-------------------------------------------------------------------------

    /**
     * 显示警告View
     */
    public void showWarningView(boolean showWarningView, String message) {
        if (warningView == null) {
            ViewStub contentViewStub = (ViewStub) findViewById(R.id.warningViewStub);
            if (contentViewStub == null) {
                return;
            }
            View inflateView = contentViewStub.inflate();
            if (inflateView == null) {
                return;
            }
            warningView = (LinearLayout) inflateView.findViewById(R.id.warningView);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, DisplayUtil.dip2px(this, 48));
            params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            warningView.setLayoutParams(params);
            TextView warningMessageView = (TextView) warningView.findViewById(R.id.warningMessageView);
            if (!StringUtil.isEmpty(message)) {
                warningMessageView.setText(message);
            }
        }

        if (showWarningView) {
            if (warningView.getVisibility() == View.VISIBLE) {
                return;
            }
            ViewCompat.setTranslationY(warningView, 0);
            warningView.setVisibility(View.VISIBLE);
        } else {
            if (warningView.getVisibility() == View.GONE) {
                return;
            }
            ViewCompat.setTranslationY(warningView, 0);
            ViewCompat.animate(warningView).translationY(-DisplayUtil.dip2px(this, 70)).setDuration(500).setListener(new SimpleViewPropertyAnimatorListener() {
                @Override
                public void onAnimationEnd(View view) {
                    warningView.setVisibility(View.GONE);
                }
            }).start();
        }
    }
//    @Subscribe
//    public void onEvent(NetworkChangeEvent event) {
//        switch (event.getStatus()) {
//            case NetworkChangeEvent.CONNECTED: {
//                displayNetworkStatusBar(false);
//                break;
//            }
//            case NetworkChangeEvent.DISCONNECTED: {
//                displayNetworkStatusBar(true);
//                break;
//            }
//        }
//    }
//
//    private void displayNetworkStatusBar(boolean display) {
//        if (mActivityLoadingFinished) {
//            if (display) {
//                if (null == mNetworkStatusBar) {
//                    mNetworkStatusBar = new PopupWindow(this);
//                    View contentView = getLayoutInflater().inflate(R.layout.fl_warning_view, null);
//                    contentView.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            try {
//                                Intent intent = new Intent(Settings.ACTION_SETTINGS);
//                                startActivity(intent);
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                            }
//                        }
//                    });
//                    mNetworkStatusBar.setContentView(contentView);
//                    mNetworkStatusBar.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
//                    mNetworkStatusBar.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
//                    mNetworkStatusBar.setBackgroundDrawable(null);
//                }
//                if (null != basetitleView) {
//                    mNetworkStatusBar.showAsDropDown(basetitleView);
//                    MemoryCache.sharedInstance().put(getClass().getName(), true);
//                }
//            } else {
//                if (null == mNetworkStatusBar) return;
//                mNetworkStatusBar.dismiss();
//                MemoryCache.sharedInstance().put(getClass().getName(), false);
//            }
//        }
//    }
//
//    @Override
//    public void onWindowFocusChanged(boolean hasFocus) {
//        super.onWindowFocusChanged(hasFocus);
//        mActivityLoadingFinished = hasFocus;
//        if (mActivityLoadingFinished) {
//            Boolean display = (Boolean) MemoryCache.sharedInstance().get(getClass().getName());
//            if (null != display && display) {
//                if (null == mCheckStatusTask) {
//                    mCheckStatusTask = new Runnable() {
//                        @Override
//                        public void run() {
//                            displayNetworkStatusBar(true);
//                        }
//                    };
//                }
//                mMainHandler.removeCallbacks(mCheckStatusTask);
//                mMainHandler.postDelayed(mCheckStatusTask, 200);
//            }
//        }
//    }
    //---------网络状态监听------end-------------------------------------------------------------------------

    /**
     * 关闭所有打开的Activity
     */
    public static void closeAllOpenedActivity() {
        if (null != openedActivities && !openedActivities.isEmpty()) {
            for (ActivityBase openedActivitie : openedActivities) {
                if (openedActivitie != null) {
                    openedActivitie.finish();
                }
            }
        }
    }

    /**
     * 关闭所有打开的Activity 除了主页面
     */
    public static void closeAllOpenedActivityNoMain() {
        if (null != openedActivities && !openedActivities.isEmpty()) {
            for (ActivityBase openedActivitie : openedActivities) {
                if (openedActivitie != null && !(openedActivitie instanceof ActivityMain)) {
                    openedActivitie.finish();
                }
                if (openedActivitie instanceof ActivityMain) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                        if (!openedActivitie.isDestroyed() || !openedActivitie.isFinishing()) {
                            ((ActivityMain) openedActivitie).selectTab(0);
                        }
                    } else {
                        if (!openedActivitie.isFinishing()) {
                            ((ActivityMain) openedActivitie).selectTab(0);
                        }
                    }
                }
            }
        }
    }
//---------广播事件处理------start-------------------------------------------------------------------------

    /**
     * 广播注册
     */
    private void registReceiver() {
        setAction();
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onReceiver(context, intent);
                actReceiver(context, intent);
            }
        };
        registerReceiver(receiver, intentFilter);
    }

    /**
     * 用于父类中处理的广播
     *
     * @param context
     * @param intent
     */
    private void actReceiver(Context context, Intent intent) {
        if (intent.getAction().equals(BroadcastFilters.BROADCAST_ACTION_SUPERMARKET_REFLUSH_DATA_ORDER)) {

        } else if (intent.getAction().equals(BroadcastFilters.BROADCAST_ACTION_NEED_RELOGIN)) {
            for (int i = 0; i < openedActivities.size(); i++) {
                if(openedActivities.get(i) instanceof ActivityLogin){
                    IntentUtil.gotoActivity(this, ActivityLogin.class);
                    return;
                }
            }
            closeAllOpenedActivityNoMain();
            UserInfoUtils.loginOut();
            ToastUtil.getInstance().showToast(this, "登录失效，请重新登录");
            IntentUtil.gotoActivity(this, ActivityLogin.class);
        } else if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
            if (isUploadServiceAlive) {
                sendBroadcast(new Intent(BroadcastFilters.BROADCAST_ACTION_UPLOAD_SERVICE_ASK));
                isUploadServiceAlive = false;
            } else {
                isUploadServiceAlive = true;
                startService(new Intent(context, UploadService.class));
            }
        } else if (intent.getAction().equals(BroadcastFilters.BROADCAST_ACTION_UPLOAD_SERVICE_ALIVE)) {
            isUploadServiceAlive = true;
        }
    }

    /**
     * 设置广播接收数据（如果有广播需要处理，需要在这里进行配置）
     */
    private void setAction() {
        intentFilter = new IntentFilter();
        BroadcastFilters.addAction(intentFilter);
    }

    public abstract void initview(@Nullable Bundle savedInstanceState);

    public abstract void initData();

    /**
     * 广播处理
     */
    public abstract void onReceiver(Context context, Intent intent);
    //---------广播事件处理------end-------------------------------------------------------------------------

//---------加载圈控制------start-------------------------------------------------------------------------

    /**
     * 显示加载页面
     *
     * @return 当前的对话框对象
     */
    public void showLoadingDialog() {
        showLoadingDialog(getString(R.string.loading));
    }

    /**
     * 显示加载页面
     *
     * @return 当前的对话框对象
     */
    public void showLoadingDialog(boolean cancancel) {
        showLoadingDialog(getString(R.string.loading), cancancel);
    }

    /**
     * 显示加载页面
     *
     * @param loadingText 加载提示文字
     * @return 当前的对话框对象
     */
    public void showLoadingDialog(String loadingText) {
        if (mDialog == null) {
            mDialog = new LoadingDialog(this);
        }
        mDialog.setTitle(loadingText);
        if (mDialog.isShowing()) {
            mDialog.dismiss();
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (this != null && (!isDestroyed() || !isFinishing())) {
                mDialog.show();
            }
        } else {
            if (this != null && !isFinishing()) {
                mDialog.show();
            }
        }
    }


    /**
     * 显示加载页面
     *
     * @param loadingText 加载提示文字
     * @return 当前的对话框对象
     */
    public void showLoadingDialog(String loadingText, boolean cancancel) {
        if (mDialog == null) {
            mDialog = new LoadingDialog(this);
        }
        mDialog.setCancelable(cancancel);
        mDialog.setTitle(loadingText);
        if (mDialog.isShowing()) {
            mDialog.dismiss();
        }
        mDialog.show();
    }

    public void dissmissLoadingDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }
    //---------加载圈控制------end-------------------------------------------------------------------------

//---------输入法控制------start-------------------------------------------------------------------------

    /**
     * 关闭软键盘
     */
    public void hideSoftKeyboard() {
        View view = getCurrentFocus();
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * 关闭软键盘
     */
    public void hideSoftKeyboard(View view) {
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * 显示软键盘
     */
    public void showSoftKeyboard() {
        View view = getCurrentFocus();
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);
        }
    }
    //---------输入法控制------end-------------------------------------------------------------------------

    //---------进行拍照获取权限回调------start-------------------------------------------------------------------------

    /**
     * 开启相机
     */
    public void requestToCamera(OnGetCameraPermissionBack listener) {
        this.listener = listener;
        ActivityBasePermissionsDispatcher.getCameraPermissionWithCheck(this);
    }

    public void toSelectTab(int i) {
        if (null != openedActivities && !openedActivities.isEmpty()) {
            for (ActivityBase openedActivitie : openedActivities) {
                if (openedActivitie instanceof ActivityMain) {
                    ((ActivityMain)openedActivitie).selectTab(i);
                }
            }
        }
    }

    /**
     * 子类如果需要调用相机，需要实现此方法进行相机拍摄
     */
    public interface OnGetCameraPermissionBack {
        void back();
    }

    public OnGetCameraPermissionBack listener;

    /**
     * 获取相机权限之后的回调
     */
    @NeedsPermission(Manifest.permission.CAMERA)
    public void getCameraPermission() {
        if (listener != null) {
            listener.back();
        }
    }

    @OnShowRationale(Manifest.permission.CAMERA)
    public void showRationaleForCamera(final PermissionRequest request) {
        request.proceed();
    }

    @OnPermissionDenied(Manifest.permission.CAMERA)
    public void deniedCameraPermission() {
        ToastUtil.getInstance().showDialog(this, getString(R.string.denied_camera_permission));
    }
    //---------进行拍照获取权限回调---------end----------------------------------------------------------------------

    //---------进行定位获取权限回调---------start----------------------------------------------------------------------

    /**
     * 开启定位
     */
    public void requestToLocation(OnGetLocationPermissionBack locationlistener) {
        this.locationlistener = locationlistener;
        ActivityBasePermissionsDispatcher.getLocationPermissionWithCheck(this);
    }

    /**
     * 子类如果需要调用相机，需要实现此方法进行相机拍摄
     */
    public interface OnGetLocationPermissionBack {
        void back();
    }

    public OnGetLocationPermissionBack locationlistener;

    @NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
    public void getLocationPermission() {
        if (locationlistener != null) {
            locationlistener.back();
        }
    }

    @OnShowRationale(Manifest.permission.ACCESS_FINE_LOCATION)
    public void showRationaleForLocation(final PermissionRequest request) {
        request.proceed();
    }

    @OnPermissionDenied(Manifest.permission.ACCESS_FINE_LOCATION)
    public void onLocationDenied() {
        ToastUtil.getInstance().showDialog(this, getString(R.string.denied_location_permission));
    }
}
